import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
// import io from 'socket.io-client';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import SocketPlugin from './socket.js'

// const socket = io('http://localhost:3000', {
//   reconnection: true,
//   reconnectionAttempts: 5,
//   reconnectionDelay: 1000,
//   reconnectionDelayMax: 5000,
//   randomizationFactor: 0.5
// }); 
// Vue.prototype.$socket = socket;
// Vue.config.productionTip = false
Vue.use(ElementUI);
Vue.use(SocketPlugin)
new Vue({
  router,
  store,
  created() {
// 连接服务器
    this.$socket.on('connect', () => {
      console.log('connected to server');
    });

   // 监听来自服务器的socketId
   this.$socket.on('socketId', (socketId) => {
    sessionStorage.setItem("socketId", socketId)
    const userid=sessionStorage.getItem('userid')
    if(userid!==null&&userid!==''){
      this.$socket.emit('update',{socketId:socketId,userid:userid})
    }
     console.log(`我的socketId是：${socketId}`,userid);
    });
    this.$socket.on('disconnect', () => {
      console.log('disconnected from server');
      this.$message('服务器连接异常')
    });
    // this.$socket.on('message', (data) => {
    //   console.log('received message:', data);
    // });
  },
  mounted() {
    // const id = sessionStorage.getItem('socketId')
    // this.$socket.on(`${id}timuserTuiChu`,(data)=>{
    //   console.log(data);
    //   // this.$alert(`${data.message}，请重新登录`, '警告', {
    //   //     confirmButtonText: '确定',
    //   //     callback: action => {
    //   //       sessionStorage.setItem("userid", '')
    //   //     }
    //   //   });
    // })
  },
  render: h => h(App)
}).$mount('#app')
// new Vue({
//   el: '#app',
 
// });
